package offer;

/**
 * 剑指 Offer 15. 二进制中1的个数
 */
public class HammingWeight {

    public static void main(String[] args) {
        int i = hammingWeight(12);
        System.out.println(i);
    }

    public static int hammingWeight(int n) {
        int num = 0;
        while (n > 0) {
            if ((n & 1) == 1) {
                num++;
            }
            n = n >>> 1;
        }
        return num;
    }
}
